package com.example.externalstoreage;

import android.app.Application;
import android.content.Context;
import android.util.Log;

import androidx.room.Room;

import com.example.externalstoreage.dao.BookDao;
import com.example.externalstoreage.database.BookDatabase;

public class MyApplication extends Application {
    public static String DATABASE_NAME = "book_database";
    public static MyApplication instance;
    private BookDatabase bookDatabase;

    public static MyApplication getInstance() {
        if (instance == null) {
            instance = new MyApplication();
        }
        return instance;
    }

    public BookDatabase getBookDatabase(Context context) {
        if (bookDatabase == null) {
            bookDatabase = Room.databaseBuilder(
                    context,
                    BookDatabase.class,
                    DATABASE_NAME
            ).allowMainThreadQueries().build();
        }
        return bookDatabase;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        Log.d("zhoutao", "My application create");

    }

}
